﻿<%@ Page Title="" Language="C#" MasterPageFile="~/styles/AdminMasterPage.master"
    AutoEventWireup="true" CodeFile="MusicManagement.aspx.cs" Inherits="Admin_MusicManagement" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <script type="text/javascript">
        var timer;
        function runPostBack() {
            __doPostBack('<%= txtAlbumName.ClientID%>', '');
            document.getElementById("txtKey").focus();
        }
        function searchArtistPostBack() {
            __doPostBack('<%= txtArtistS.ClientID%>', '');
            document.getElementById("txtKey").focus();
        }
        function searchAlbumPostBack() {
            __doPostBack('<%= txtAlbumS.ClientID%>', '');
            document.getElementById("txtKey").focus();
        }
        function getFocus() {
            var text = document.getElementById("txtKey");
            if (text != null && text.value.length > 0) {
                if (text.createTextRange) {
                    var FieldRange = text.createTextRange();
                    FieldRange.moveStart('character', text.value.length);
                    FieldRange.collapse();
                    FieldRange.select();
                }
            }
        }
        function setDelay() {
            clearTimeout(timer);
            timer = setTimeout("runPostBack()", 1000);
        }
        function setDelaySearchArtist() {
            clearTimeout(timer);
            timer = setTimeout("searchArtistPostBack()", 1000);
        }
        function setDelaySearchAlbum() {
            clearTimeout(timer);
            timer = setTimeout("searchAlbumPostBack()", 1000);
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="TopContent" runat="Server">
    <h3 class="titleDetails">
        Music Management</h3>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="Server">
    <div class="buttonStyleGroup1">
        <ul>
            <li><a id="lnkAdd" class="buttonStyle1" runat="server">Add</a></li>
            <li><a id="lnkFind" class="buttonStyle1" runat="server">Find</a></li>
        </ul>
    </div>
    <div id="AddPanel" class="controlBox" style="display:none;" runat="server">
        <h3>
            New Music</h3>
        <table>
            <tr>
                <td width="140">
                    Album:
                </td>
                <td width="400" style="margin-left: 40px">
                    <asp:TextBox ID="txtAlbumID" runat="server" ReadOnly="True" 
                        BorderColor="#00CC99"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtAlbumID"
                        ErrorMessage="RequiredFieldValidator" ValidationGroup="valdGroup">(*)</asp:RequiredFieldValidator>
                    <br />
                    <br />
                    Search by Title:<br />
                    <asp:TextBox ID="txtAlbumName" runat="server" onkeyup="setDelay();" OnTextChanged="Search"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    Title:
                </td>
                <td>
                    <asp:TextBox ID="txtTitle" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator"
                        ControlToValidate="txtTitle" ValidationGroup="valdGroup">(*)</asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    Genres:
                </td>
                <td>
                    <asp:DropDownList ID="lst_Genres" runat="server">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    Music File
                </td>
                <td>
                    <asp:AsyncFileUpload ID="AsyncFileUpload1" runat="server" />
                </td>
            </tr>
            <tr>
                <td>
                    Image Cover
                </td>
                <td>
                    <asp:AsyncFileUpload ID="AsyncFileUpload2" runat="server" />
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                    <asp:Button ID="btnSubmit" CssClass="buttonStyle1" runat="server" Text="Submit" OnClick="AddNewMusic"
                        ValidationGroup="valdGroup" />
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                    <asp:Label ID="lblResult" runat="server" Text=""></asp:Label>
                </td>
            </tr>
        </table>
    </div>
    <div id="FindPanel" class="controlBox" style="display:none;" runat="server">
        <h3>
        Find Music</h3>
        <table>
            <tr>
                <td width="150">Title:</td>
                <td width="300">
                    <asp:TextBox ID="txtTitleS" runat="server"></asp:TextBox></td>
            </tr>
            <tr>
                <td>Artist:</td>
                <td><asp:TextBox ID="txtArtistS" runat="server" onkeyup="setDelaySearchArtist();" OnTextChanged="SearchArtist"></asp:TextBox></td>
            </tr>
            <tr>
                <td>Album:</td>
                <td><asp:TextBox ID="txtAlbumS" runat="server" onkeyup="setDelaySearchAlbum();" OnTextChanged="SearchtAlbum"></asp:TextBox></td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <asp:Button ID="btnFind" CssClass="buttonStyle1" runat="server" Text="Search" OnClick="SearchMusic" /></td>
            </tr>
        </table>
    </div>
    <div style="width: 98%; margin: 0 auto 40px; padding: 20px 0 0 10px;">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:GridView ID="grvw_Music" runat="server" CellPadding="4" ForeColor="#333333"
                    GridLines="None" AllowPaging="True" OnPageIndexChanging="grvw_Music_PageIndexChanging"
                    AutoGenerateColumns="False" Width="98%" AutoGenerateDeleteButton="False" 
                    AutoGenerateEditButton="False" onrowcancelingedit="grvw_Music_RowCancelingEdit" 
                    onrowediting="grvw_Music_RowEditing">
                    <AlternatingRowStyle BackColor="White" />
                    <Columns>
                        <asp:BoundField DataField="MusicID" HeaderText="ID">
                            <ControlStyle Width="40px" />
                        </asp:BoundField>
                        <asp:ImageField DataImageUrlField="Cover" HeaderText="Image Cover">
                            <ControlStyle Width="60px" />
                        </asp:ImageField>
                        <asp:BoundField DataField="Title" HeaderText="Title">
                            <ControlStyle Width="150px" />
                        </asp:BoundField>
                        <asp:BoundField DataField="ArtistName" HeaderText="Artist">
                            <ControlStyle Width="150px" />
                        </asp:BoundField>
                        <asp:BoundField DataField="AlbumName" HeaderText="Album">
                            <ControlStyle Width="150px" />
                        </asp:BoundField>
                        <asp:BoundField DataField="GenresName" HeaderText="Genres">
                            <ControlStyle Width="150px" />
                        </asp:BoundField>
                    </Columns>
                    <EditRowStyle BackColor="#2461BF" />
                    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                    <RowStyle BackColor="#EFF3FB" />
                    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                    <SortedAscendingCellStyle BackColor="#F5F7FB" />
                    <SortedAscendingHeaderStyle BackColor="#6D95E1" />
                    <SortedDescendingCellStyle BackColor="#E9EBEF" />
                    <SortedDescendingHeaderStyle BackColor="#4870BE" />
                </asp:GridView>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    <asp:UpdatePanel ID="UpdatePanel2" runat="server">
        <ContentTemplate>
            <div id="SearchResultPanel" class="SearchResultPanel" runat="server">    
                <h3 id="albummTitle" runat="server"></h3>            
                <div id="album_mdiv" class="album_mdiv" runat="server">                    
                    <h3>
                        Select Album</h3>
                    <asp:Repeater ID="Rpt_Album_m" runat="server">
                        <HeaderTemplate>
                            <ul>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <li>
                                <img src="<%# Eval("AlbumCover")%>" alt="" />
                                <span>
                                    <asp:LinkButton ID="lnkSelectAlbum" runat="server" CommandArgument='<%# Eval("AlbumID")%>'
                                        OnCommand="SetSelectedAlbum"><%# Eval("AlbumName")%> - <%# Eval("ArtistName")%></asp:LinkButton></li>
                        </ItemTemplate>
                        <FooterTemplate>
                            </ul></FooterTemplate>
                    </asp:Repeater>
                </div>
            </div>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="txtAlbumName" EventName="TextChanged" />
        </Triggers>
    </asp:UpdatePanel>
    <asp:UpdatePanel ID="UpdatePanel3" runat="server">
        <ContentTemplate>
            <div id="SearchAlbumPanel" class="SearchResultPanel" runat="server">
                <asp:Button ID="btnHide" style="float:right;margin-right:10px;" runat="server" Text="Hide" OnClick="HidePanel" />
                <h3 id="albumsTitle" runat="server"></h3>
                <div id="album_sdiv" class="album_mdiv" runat="server">
                    <h3>
                        Select Album</h3>
                    <asp:Repeater ID="Rpt_Album_s" runat="server">
                        <HeaderTemplate>
                            <ul>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <li>
                                <img src="<%# Eval("AlbumCover")%>" alt="" />
                                <span>
                                    <asp:LinkButton ID="lnkSelectAlbum" runat="server" CommandArgument='<%# Eval("AlbumID")%>'
                                        OnCommand="SetSelectedAlbumSearh"><%# Eval("AlbumName")%> - <%# Eval("ArtistName")%></asp:LinkButton></li>
                        </ItemTemplate>
                        <FooterTemplate>
                            </ul></FooterTemplate>
                    </asp:Repeater>
                </div>
            </div>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="txtAlbumS" EventName="TextChanged" />
            <asp:AsyncPostBackTrigger ControlID="txtArtistS" EventName="TextChanged" />
        </Triggers>
    </asp:UpdatePanel>
</asp:Content>
